import com.alibaba.fastjson.JSON;
import com.cangshi.entity.Task;
import com.cangshi.entity.TaskPosition;
import com.cangshi.service.TaskPositionService;
import com.cangshi.service.TaskService;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by 15c on 2017/4/3.
 */
@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration(locations = {"classpath:spring-config.xml", "classpath:spring-mybatis.xml"})
public class TaskTest {
    private static final Logger LOGGER = Logger.getLogger(UserTest.class);

    @Autowired
    TaskService taskService;
    @Autowired
    TaskPositionService taskPositionService;
    @Test
    public void TestaddTask(){
        Task task=new Task();
        task.setTaskCreator(1);//此处id应该为获取的userId
        task.setTaskCondition("学习成绩要好！");
        task.setTaskContactInfo("110");
        task.setTaskContent("帮取快递");
        task.setTaskMoney(0.5);
       int i= taskService.addTask(task);
        taskService.getLastTaskId();
        if(i==1){
            System.out.print("成功创建一条任务;Id为:"+ taskService.getLastTaskId());
            LOGGER.info("<<<<<<<<<<<<<<" + JSON.toJSON(task) + ">>>>>>>>>>>>>>>");
        } else {
            System.out.print("创建任务失败！");
        }
    }
    @Test
    public void TestgetLastTaskId(){
        System.out.print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" + taskService.getLastTaskId());
    }
    @Test
    public void TestselectUserCreateHistoryTaskBYUserId(){
        List<Task> list=new LinkedList<Task>();
    list=taskService.selectUserCreateHistoryTaskBYUserId(0,2,18);
        LOGGER.info("<<<<<<<<<<<<<<" + JSON.toJSON(list) + ">>>>>>>>>>>>>>>");
    }

    /**
     * 测试修改任务状态
     */
    @Test
    public void TestupdateTaskState(){

     int i=   taskService.updateTaskState(4,2,1);
        System.out.print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" + i);
    }

    @Test
    public void TestdeleteTask(){
        taskService.deleteTask(30);
        System.out.print("<<<<<<<<<<删除成功");
    }
    @Test
    public  void  TestinsertXandY(){
        TaskPosition taskPosition=new TaskPosition();
        taskPosition.setPositonY(200.0);
        taskPosition.setPositionX(100.0);
        taskPositionService.insertXandY(taskPosition);

    }
    @Test
    public void TestselectTaskDetails(){

        LOGGER.info("<<<<<<<<<<<<<<" + JSON.toJSON(taskService.selectTaskDetails(26)) + ">>>>>>>>>>>>>>>");
    }

    /**
     * 测试查询筛选出的任务总条数
     */
    @Test
    public void TestselectAllNumber(){
       int i=taskService.selectAllNumber(null,null,null,150000000,"yi",30.6452350000,104.3354830000);
        int a=i/2;
        int b=i%2;
        if (b>0){
            a=a+1;
        }


        System.out.print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<任务总数" + i + ">>>>>>>>>>>>>>>>>>>总页数" + a);
    }
    /**
     * 测试筛选任务分页
     */

    @Test
    public void TestselectTaskByScreen(){

        LOGGER.info("<<<<<<<<<<<<<<" + JSON.toJSON(taskService.selectTaskByScreen(null, null, null, 1503528, null, 2, 2, 30.6452350000, 104.3354830000)) + ">>>>>>>>>>>>>>>");
    }


    @Test
    public void TestselectHomePageTaskNum(){
        int i=taskService.selectHomePageTaskNum();
        System.out.print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<任务总数" + i);
    }
    @Test
    public  void  TestselectHomePageTask(){
        List<Task> list=new LinkedList<Task>();
        list=taskService.selectHomePageTask(0,5);
        LOGGER.info("<<<<<<<<<<<<<<五条任务是：" + JSON.toJSON(list) + ">>>>>>>>>>>>>>>");
    }


    @Test
    public void TestTaskOverdue(){
        System.out.print("任务过期条数：" + taskService.setTaskOverdue());
    }

    /**
     * -
     */
    @Test
    public  void TestselectTaskNumByLandUser(){
        int i=taskService.selectTaskNumByLandUser(null, null, null, 1561560156, null, 30.6452350000, 104.3354830000,0,null);
        System.out.print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"+i);
    }


}
